import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
import 'package:ytbusiness/config/style.dart';
import 'package:ytbusiness/config/yt_theme.dart';
import 'package:ytbusiness/page/repair_factory/repair_order/order_widget/repair_car_info.dart';
import 'package:ytbusiness/page/repair_factory/repair_order/order_widget/repair_order_info.dart';
import 'package:ytbusiness/utils/screen_adaptation.dart';

///新维修订单  / 已确认，待定损
class PushRepairDetails extends StatefulWidget {
  //{type,title}
  final Map<String, dynamic> arguments;

  const PushRepairDetails({Key key, this.arguments}) : super(key: key);

  @override
  _PushRepairDetailsState createState() => _PushRepairDetailsState();
}

class _PushRepairDetailsState extends State<PushRepairDetails>
    with TickerProviderStateMixin {
//  AnimationController controller;//动画控制器
//  Animation<double> boxAnimation;//补间
  TabController _tabController; //tab控制器
  List<String> titleList = ["订单信息", "车辆信息"];
  List<String> orderInfo = [
    "订单编号",
    "订单时间",
    "推修来源",
    "车辆型号",
    "车辆牌号",
    "订单状态"
  ]; //訂單信息
  List<String> carInfo = [
    "车型识别码",
    "主机厂",
    "车辆型号",
    "销售名称",
    "年款",
    "变速箱",
    "前制动器类型",
    "后制动器类型",
    "发动机型号",
    "进气形式",
    "燃油类型",
    "厂商指导价格",
    "底盘号",
    "车辆类型",
    "轮胎规格"
  ]; //车辆信息

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
//    controller = AnimationController(
//        duration: const Duration(milliseconds: 100), //动画持续的时长
//        vsync: this   //作用的statefulWidget实例
//    );
//    boxAnimation = new Tween<double>(begin: (orderInfo.length*38).toDouble(), end: (carInfo.length*38).toDouble()).animate(controller)
//      ..addListener(() {
//        setState(() {
//          print(boxAnimation.value);
//        });
//      });

    _tabController = new TabController(length: 2, vsync: this);

    _tabController.addListener(() {
      setState(() {});
//      if(_tabController.index == 0){
//        controller.reverse();
//      }else{
//        controller.forward();
//      }
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: YTStyle.bgColor,
      appBar: AppBar(
        elevation: 0.5,
        centerTitle: true,
        backgroundColor: Colors.white,
        title: Text(
          widget.arguments["title"] as String,
          style: TextStyle(
              color: Color(0xff323232),
              fontSize: setSp(18),
              fontWeight: FontWeight.w600),
          maxLines: 1,
          overflow: TextOverflow.ellipsis,
        ),
        bottom: TabBar(
          controller: _tabController,
          isScrollable: true,
          labelColor: YTTheme.theme,
          labelStyle:
              TextStyle(fontSize: setSp(17), fontWeight: FontWeight.w600),
          unselectedLabelColor: Color(0xff323232),
          unselectedLabelStyle:
              TextStyle(color: Colors.white, fontSize: setSp(17)),
          indicatorColor: YTTheme.theme,
          indicatorSize: TabBarIndicatorSize.label,
          tabs: titleList
              .asMap()
              .map((key, value) {
                return MapEntry(key, _tabItem(titleList[key]));
              })
              .values
              .toList(),
        ),
        leading: GestureDetector(
          behavior: HitTestBehavior.opaque,
          onTap: () {
            Navigator.pop(context);
          },
          child: Row(
            children: [
              Container(
                  margin: EdgeInsets.only(left: setWidth(15)),
                  width: setWidth(10),
                  height: setWidth(17),
                  child: Image.asset(
                    "assets/images/return.png",
                    fit: BoxFit.cover,
                  )),
            ],
          ),
        ),
        actions: [
          Container(
            margin: EdgeInsets.only(right: setWidth(15)),
            width: setWidth(10),
            height: setWidth(17),
          ),
        ],
      ),
      body: CustomScrollView(
        slivers: [
          SliverToBoxAdapter(
            child: SizedBox(
              height: setWidth(15),
            ),
          ),
          SliverToBoxAdapter(
            child: Container(
              padding: EdgeInsets.only(
                  left: setWidth(15),
                  right: setWidth(15),
                  bottom: setWidth(15)),
              color: Colors.white,
              child: _checkType(_tabController.index),
            ),
          ),
//          SliverToBoxAdapter(
//            child: Container(
//              height: boxAnimation.value,
//              child: TabBarView(
//                controller: _tabController,
//                physics: NeverScrollableScrollPhysics(),
//                children: [
//                  Container(
//                    padding: EdgeInsets.only(
//                        left: setWidth(15),
//                        right: setWidth(15),),
//                    color: Colors.white,
//                    child: RepairOrderInfo(),
//                  ),
//                  Container(
//                    padding: EdgeInsets.only(
//                        left: setWidth(15),
//                        right: setWidth(15)),
//                    color: Colors.white,
//                    child: RepairCarInfo(),
//                  ),
//                ],
//              ),
//            ),
//          ),
          SliverToBoxAdapter(
            child: SizedBox(
              height: setWidth(15),
            ),
          ),
          SliverToBoxAdapter(
              child: Container(
            padding: EdgeInsets.only(
                left: setWidth(15),
                top: setWidth(20),
                bottom: setWidth(20),
                right: setWidth(15)),
            color: Colors.white,
            child: Column(
              mainAxisAlignment: MainAxisAlignment.start,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Container(
                  margin: EdgeInsets.only(
                    bottom: setWidth(20),
                  ),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.start,
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: [
                      Container(
                        width: setWidth(2.5),
                        height: setWidth(15),
                        color: Color(0xff00C65F),
                      ),
                      Container(
                        child: Text("事故图片"),
                        margin: EdgeInsets.only(left: setWidth(10)),
                      ),
                    ],
                  ),
                ),
                Container(
                  child: StaggeredGridView.countBuilder(
                    physics: NeverScrollableScrollPhysics(),
                    shrinkWrap: true,
                    crossAxisCount: 3,
                    mainAxisSpacing: setWidth(10),
                    crossAxisSpacing: setWidth(10),
                    staggeredTileBuilder: (i) {
                      return StaggeredTile.fit(1);
                    },
                    itemCount: 6,
                    itemBuilder: (context, index) {
                      return GestureDetector(
                          onTap: () {}, child: _gridItem(index));
                    },
                  ),
                ),
              ],
            ),
          ))
        ],
      ),
    );
  }

//  @override
//  void dispose() {
//    // TODO: implement dispose
//    super.dispose();
//    controller.dispose();//释放动画
//  }

  // ignore: missing_return
  Widget _checkType(int type) {
    switch (type) {
      case 0:
        return RepairOrderInfo(orderState: widget.arguments["title"] as String);
        break;
      case 1:
        return RepairCarInfo();
        break;
    }
  }

  Widget _tabItem(String title) {
    return Tab(text: title);
  }

  //图片
  Widget _gridItem(int index) {
    return Container(
      width: setWidth(109.5),
      height: setWidth(73.5),
      color: Colors.black,
    );
  }
}
